package com.youfang.sixthmedia.message;

import java.util.LinkedList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.youfang.sixthmedia.message.model.MessageBean;
import com.youfang.sixthmedia.net.Response;

public class HousefilterResponse extends Response {

	// type=0 物业类型
	public static class HouseType implements MessageBean {
		public String housetypename;
		public int housetypeid;
	}

	// type=1 区域版块
	public static class Area implements MessageBean {
		public int cityid;
		public String cityname;
		public String citytype;
		public int parentid;
		public int flag;

	}

	// type=2 价位区间
	public static class Price implements MessageBean {

		public int pricerangeid;
		public int pricemin;
		public int pricemax;
		public String pricedesc;

	}

	private List<HouseType> houseTypeList = new LinkedList<HouseType>();
	private List<Area> areaList = new LinkedList<Area>();
	private List<Price> priceList = new LinkedList<Price>();

	// init some psuedo object
	final public static HouseType HT = new HouseType();
	final public static Area AREA = new Area();
	final public static Price PRICE = new Price();

	{

		HT.housetypeid = 0;
		HT.housetypename = "不限";
		houseTypeList.add(HT);

		AREA.cityid = 0;
		AREA.cityname = "不限";
		areaList.add(AREA);

		PRICE.pricerangeid = 0;
		PRICE.pricedesc = "不限";

		priceList.add(PRICE);

	}

	// this searcher filter is bound to a specific filter...
	private int cityId;

	public int getCityId() {
		return cityId;
	}

	public void setBoundCityId(int cityId) {
		this.cityId = cityId;
	}

	@Override
	protected void decodeBody(JSONObject bodyJSON) throws Exception {

		JSONArray classlist = bodyJSON.getJSONArray("classlist");
		for (int i = 0; i < classlist.length(); i++) {
			JSONObject obj = classlist.getJSONObject(i);
			int type = obj.getInt("type");
			JSONArray datatypes = obj.getJSONArray("typelist");
			for (int j = 0; j < datatypes.length(); j++) {
				JSONObject o = datatypes.getJSONObject(j);

				switch (type) {
				case 0:

					HouseType ht = new HouseType();
					ht.housetypeid = getInt(o, "housetypeid");
					ht.housetypename = getString(o, "housetypename");
					houseTypeList.add(ht);

					break;
				case 1:

					Area area = new Area();
					area.cityid = getInt(o, "cityid");
					area.cityname = getString(o, "cityname");
					area.citytype = getString(o, "citytype");
					area.flag = getInt(o, "flag");
					area.parentid = getInt(o, "parentid");
					areaList.add(area);

					break;
				case 2:
					Price price = new Price();
					price.pricedesc = getString(o, "pricedesc");
					price.pricemax = getInt(o, "pricemax");
					price.pricemin = getInt(o, "pricemin");
					price.pricerangeid = getInt(o, "pricerangeid");
					priceList.add(price);

					break;

				}

			}
		}

	}

	public List<HouseType> getHouseTypeList() {
		return houseTypeList;
	}

	public void setHouseTypeList(List<HouseType> houseTypeList) {
		this.houseTypeList = houseTypeList;
	}

	public List<Area> getAreaList() {
		return areaList;
	}

	public void setAreaList(List<Area> areaList) {
		this.areaList = areaList;
	}

	public List<Price> getPriceList() {
		return priceList;
	}

	public void setPriceList(List<Price> priceList) {
		this.priceList = priceList;
	}

}
